package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.atguigu.srb.exception.Assert;
import com.atguigu.srb.result.R;
import com.atguigu.srb.result.ResponseEnum;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author fun
 * @since 2021-10-29
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Autowired
    BorrowerService borrowerService;


    @GetMapping("/list/{page}/{limit}")
    public R list(@PathVariable("page") Long page,@PathVariable("limit") Long limit,String keyword){
        Page<Borrower> borrowerPage = new Page(page, limit);
        Page<Borrower> pageModel = borrowerService.pageList(borrowerPage,keyword);
        return R.ok().data("pageModel",pageModel);
    }

    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") Long id){
        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailVOById(id);
            return R.ok().data("borrowerDetailVO",borrowerDetailVO);
    }


    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approval(borrowerApprovalVO);
        return R.ok();
    }

}

